package com.zhongmai.yzfgrabanorder.Adapter;

import android.content.Context;
import android.os.CountDownTimer;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zhongmai.yzfgrabanorder.R;
import com.zhongmai.yzfgrabanorder.bean.AppealOrderItemBean;
import com.zhongmai.yzfgrabanorder.utils.LogUtils;
import com.zhongmai.yzfgrabanorder.utils.Utils;

import java.util.List;

/**
 * 项目名称：YZFGrabAnOrder
 * 类描述：申诉订单列表适配器
 * 创建人：Administrator
 * 创建时间：2020/10/19 11:06
 * 修改人：Administrator
 * 修改时间：2020/10/19 11:06
 * 修改备注：
 */
public class AppealRecyclerViewAdapter extends RecyclerView.Adapter<AppealRecyclerViewAdapter.ViewHolder> {
    private Context mContext;
    private List<AppealOrderItemBean> mList;
    private AppealOrderItemBean data;
    private OnItemClikListener mOnItemClikListener;


    public AppealRecyclerViewAdapter(Context context, List<AppealOrderItemBean> mList) {
        this.mContext = context;
        this.mList = mList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_appeal_order, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }


    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        LogUtils.bugMes("ordersList.get---" + position, 5);
        data = mList.get(position);


        holder.mTV_order_id.setText(data.getOrderId());
        holder.mTV_order_time.setText(Utils.formatTime(data.getStartTime()));
        holder.mTV_order_money.setText(data.getMoney());
        holder.mTV_appeal_processor.setText("订单处理人：" + data.getUserName());
        getOrderResult(data.getState(), holder.mTV_order_result);

        if (mOnItemClikListener != null) {
            // 设置item条目短按点击事件的监听
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClikListener.onItemClik(holder.itemView, pos);
                }
            });

            // 设置item条目长按点击事件的监听
            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClikListener.onItemLongClik(holder.itemView, pos);
                    return false;
                }
            });
        }
    }

    private void getOrderResult(int state, TextView mTV_order_result) {
        switch (state) {
            case 0:
                mTV_order_result.setText("成功");
                mTV_order_result.setTextColor(mContext.getResources().getColor(R.color.tab_background));
                break;
            case 4:
                mTV_order_result.setText("待处理");
                mTV_order_result.setTextColor(mContext.getResources().getColor(R.color.CS_delete_red));
                break;
            case 6:
                mTV_order_result.setText("待确认");
                mTV_order_result.setTextColor(mContext.getResources().getColor(R.color.appdetail_video_seekbar_bg_one));
                break;
        }
    }


    public static class ViewHolder extends RecyclerView.ViewHolder {

        private TextView mTV_order_id;
        private TextView mTV_order_time;
        private TextView mTV_order_money;
        private RelativeLayout mRL_item_click;
        private TextView mTV_order_result;
        private TextView mTV_appeal_processor;

        public ViewHolder(View itemView) {
            super(itemView);
            mTV_order_id = itemView.findViewById(R.id.mTV_order_id);
            mTV_order_time = itemView.findViewById(R.id.mTV_order_time);
            mTV_order_money = itemView.findViewById(R.id.mTV_order_money);
            mRL_item_click = itemView.findViewById(R.id.mRL_item_click);
            mTV_order_result = itemView.findViewById(R.id.mTV_order_result);
            mTV_appeal_processor = itemView.findViewById(R.id.mTV_appeal_processor);
        }
    }

    // 定义item条目点击事件接口
    public interface OnItemClikListener {
        void onItemClik(View view, int position);

        void onItemLongClik(View view, int position);

    }

    public void setItemClikListener(OnItemClikListener mOnItemClikListener) {
        this.mOnItemClikListener = mOnItemClikListener;
    }

}
